package com.heima.wemedia.controller;

import com.heima.model.admin.dto.SensitiveDto;
import com.heima.model.admin.entity.AdSensitive;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.dtos.WmNewsPageReqDto;

import com.heima.model.wemedia.entity.WmSensitive;
import com.heima.wemedia.service.WmSensitiveService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 自媒体敏感词表(WmSensitive)表控制层
 *
 * @author makejava
 * @since 2022-04-27 11:53:30
 */
@RestController
@RequestMapping("api/v1/sensitive")
public class WmSensitiveController {
    /**
     * 服务对象
     */
    @Resource
    private WmSensitiveService wmSensitiveService;

    /**
     * 查询敏感词列表
     * @param dto
     * @return
     */
    @PostMapping("list")
    public ResponseResult list(@RequestBody SensitiveDto dto){
        return wmSensitiveService.list(dto);
    }

    /**
     * 保存敏感词列表
     * @param dto
     * @return
     */
    @PostMapping("save")
    public ResponseResult save(@RequestBody SensitiveDto dto){
        return wmSensitiveService.save(dto);
    }

    /**
     * 编辑敏感词列表
     * @param wmSensitive
     * @return
     */
    @PostMapping("update")
    public ResponseResult update(@RequestBody WmSensitive wmSensitive){
        return ResponseResult.okResult(wmSensitiveService.update(wmSensitive));
    }

    /**
     * 删除敏感词列表
     * @param id
     * @return
     */
    @DeleteMapping("del/{id}")
    public ResponseResult delete(@PathVariable Integer id){
        return ResponseResult.okResult(wmSensitiveService.deleteById(id));
    }

    /**
     * 分页查询
     *
     * @param wmSensitive 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<WmSensitive>> queryByPage(WmSensitive wmSensitive, PageRequest pageRequest) {
        return ResponseEntity.ok(this.wmSensitiveService.queryByPage(wmSensitive, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<WmSensitive> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.wmSensitiveService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param wmSensitive 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<WmSensitive> add(WmSensitive wmSensitive) {
        return ResponseEntity.ok(this.wmSensitiveService.insert(wmSensitive));
    }

    /**
     * 编辑数据
     *
     * @param wmSensitive 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<WmSensitive> edit(WmSensitive wmSensitive) {
        return ResponseEntity.ok(this.wmSensitiveService.update(wmSensitive));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.wmSensitiveService.deleteById(id));
    }



}

